// Using jQuery with Other Libraries
try {
jQuery.noConflict();

// Blogger extensions Options
var BloggerExtOptions = {
    core_version: '0.6.2b'
};

var BloggerExt = {};
jQuery.extend( BloggerExt, {
        extensions: [],
        hooks: [],

        register: function(flag, opts) {
            BloggerExt.extensions.push(flag);
            if(opts) { jQuery.extend(BloggerExtOptions, opts); }
        },
        
        registerHook: function (fn) {
            BloggerExt.hooks.push(fn);
        },

        process: function() {
            jQuery(document).ready( function(){
                var flag;
                while( flag = BloggerExt.extensions.pop() ) {
                    if(BloggerExtOptions[flag]) { try { BloggerExt[flag](); }catch(e){} }
                }
                // run hooks
                BloggerExt.processHook();
            });
        },

        processHook: function() {
            // Try hook Blogger _WidgetManager_HandleControllerResult
            if(BloggerExt.isListMode() && (typeof BloggerExt._WidgetManager_HandleControllerResult == 'undefined') ) {
                BloggerExt._WidgetManager_HandleControllerResult = _WidgetManager._HandleControllerResult;
                _WidgetManager._HandleControllerResult = function() {
                    try {
                        // Call _WidgetManager_HandleControllerResult
                        BloggerExt._WidgetManager_HandleControllerResult.apply(this, arguments);
                        // call register hooks
                        while (fn = BloggerExt.hooks.pop()) { fn.call(this); }
                    }catch(e) {
                    }
                }
            }
        },

        registerAndProcess: function(flag, opts) {
            BloggerExt.register(flag,opts);
            BloggerExt.process();
        },

        isListMode: function() {
            var isList = false;
            if ( document.location.href.split('/').pop() == "" || document.location.href.split('/').pop() == "index.html") {
                // Suppose the url include index.html
                isList = true;
            }else if(document.location.href.indexOf("/search/label/") >= 0) {
                // Suppose the url  search label
                isList = true;
            }else if((document.location.href.indexOf("/search?") >= 0) || (document.location.href.indexOf("archive.html") >= 0)) {
                // Suppose the url include search or archive
                isList = true;
            }
            return isList;
        },

        isItemMode: function() {
            return (!BloggerExt.isListMode());
        }
});

// Register hide_navbar
BloggerExt.hide_navbar = function() {
    if(BloggerExtOptions.fade_navbar) {
        jQuery('#navbar').fadeTo(0,0).hover( function() { $(this).fadeTo("fast", 1); }, function() { $(this).fadeTo("fast", 0); }); 
    }else {
        jQuery('#navbar').hide();
    }
};
BloggerExt.register('hide_navbar', { hide_navbar: true, fade_navbar: false} );


// Register hide_sidebar_html_markup
BloggerExt.hide_sidebar_html_markup = function() {
    jQuery('.HTML').each( function(i) {
            jQuery('.title', this).contains('##HIDEME##').each( function(){ jQuery(this).hide(); } );
    });
};
BloggerExt.register('hide_sidebar_html_markup', { hide_sidebar_html_markup: true} );


// Register sidebar_widget_expandable
BloggerExt.sidebar_widget_expandable = function() {

    // find containers to expandable.
    jQuery.each(BloggerExtOptions.sidebar_widget_expandable_ids, function(i) {
        // find widget container with class name
        jQuery('#'+this).each( function(j){
                var widgetId = this.id;
                var titleObj = jQuery(this).children('h2:eq(0)');
                var contentObj = jQuery(this).children('div:eq(0)');
				var animate_str = "";
				if(BloggerExtOptions.sidebar_widget_expandable_animate) {
					var animate_str = "'fast',";
				}else {
					var animate_str = ").each(";
				}
                var link = "<span class=\"sidebar-widget-expand\"><a onclick=\"jQuery('#"+widgetId+" .widget-content').toggle("+animate_str
					      +"function(){ "
                          +"  jQuery(this).is(':hidden') ? "
                          +"  jQuery('#"+widgetId+" a:eq(0)').html(BloggerExtOptions.sidebar_widget_expan_title) : "
                          +"  jQuery('#"+widgetId+" a:eq(0)').html(BloggerExtOptions.sidebar_widget_collapse_title)"
                          +"});\">"+BloggerExtOptions.sidebar_widget_expan_title+"</a></span>";
                titleObj.prepend(link);
                contentObj.hide();
        });
    });

};
BloggerExt.register('sidebar_widget_expandable' ,  {
	sidebar_widget_expandable: true,
	sidebar_widget_expandable_version: 1.0,
	sidebar_widget_expandable_animate: false,
    sidebar_widget_expan_title: '[+]',
    sidebar_widget_collapse_title: '[-]',
    sidebar_widget_expandable_ids: ['Label1','LinkList1','BlogArchive1']
});


// Register replace_smiley
BloggerExt.replace_smiley = function() {

    jQuery('div.blog-posts').find('.post-body, .comment-body, .comment-body-author').each( function (i) {
            var newHtml = jQuery(this).html();
            for( var idx in BloggerExtOptions.smilies ) {
                newHtml = newHtml.replace(BloggerExtOptions.smilies[idx][0], BloggerExtOptions.smilies[idx][1], "gm");
            }
            jQuery(this).html( newHtml );
    });

};
BloggerExt.register('replace_smiley' ,  {
    replace_smiley: true,

    smilies: [
                [' :)', ' <img src="http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons7/1.gif" style="border:0; margin:0; padding:0;" /> '],
                [' :(', ' <img src="http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons7/2.gif" style="border:0; margin:0; padding:0;" /> '],
                [' ;)', ' <img src="http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons7/3.gif" style="border:0; margin:0; padding:0;" /> '],
                [' :D', ' <img src="http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons7/4.gif" style="border:0; margin:0; padding:0;" /> '],
                [' :p', '<img src="http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons7/10.gif" style="border:0; margin:0; padding:0;" /> '],
                [' :$', ' <img src="http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons7/32.gif" style="border:0; margin:0; padding:0;" /> '],
                [' :-k', ' <img src="http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons7/11.gif" style="border:0; margin:0; padding:0;" /> '],
                [' :*', ' <img src="http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons7/11.gif" style="border:0; margin:0; padding:0;" /> '],
                [' :@', ' <img src="http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons7/14.gif" style="border:0; margin:0; padding:0;" /> '],
                [' :#', ' <img src="http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons7/33.gif" style="border:0; margin:0; padding:0;" /> '],
                [' [-(', ' <img src="http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons7/33.gif" style="border:0; margin:0; padding:0;" /> '],
                [' :x', ' <img src="http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons7/35.gif" style="border:0; margin:0; padding:0;" /> '],
                [' :o', ' <img src="http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons7/13.gif" style="border:0; margin:0; padding:0;" /> ']
             ]
});
BloggerExt.registerHook(BloggerExt.replace_smiley);


// Register replace_continue_markup
BloggerExt.replace_continue_markup = function() {
    // make continue...
	if(BloggerExtOptions.replace_continue_markup_animate) {
		var animate_str = "'fast',";
	}else {
		var animate_str = ").each(";
	}
    if( BloggerExt.isListMode() ) {
        jQuery('div.post-body').contains('##CONTINUE##').each( function (i) {
            if (BloggerExtOptions.replace_continue_markup_as_link) {
                var postSummaryLength =  jQuery(this).html().indexOf('##CONTINUE##');
                var postLinkHtml = "<span class='post-body-continue'><a href='"
                                  +jQuery(this).parent().find('.post-title a').attr('href')
                                  +"'>"+BloggerExtOptions.continue_markup_expand_title+"</a></span>";
                jQuery(this).html( jQuery(this).html().substr(0, postSummaryLength) + postLinkHtml );
            }else {
                var postLinkHtml = "<span class=\"post-body-continue\"><a id=\"post-body-toggle" + i + "\" onclick=\"jQuery('#post-body-hide"
                                  +i+"').toggle("+animate_str
								  +"function(){"
								  +"  jQuery(this).is(':hidden') ?"
                                  +"    jQuery('#post-body-toggle"+i+"').html(BloggerExtOptions.continue_markup_expand_title) : "
                                  +"    jQuery('#post-body-toggle"+i+"').html(BloggerExtOptions.continue_markup_collapse_title)"
                                  +"});\">"+BloggerExtOptions.continue_markup_expand_title+"</a></span>"
                                  +"<div style='display:none' id='post-body-hide"+i+"'>";
                jQuery(this).html( (jQuery(this).html().replace(/##CONTINUE##/g, postLinkHtml)) + "</div>");
            }
        });

    }else {
        jQuery('div.post-body').contains('##CONTINUE##').each( function (i) {
            jQuery(this).html(jQuery(this).html().replace(/##CONTINUE##/g,""));
        });
    }

    // support make continue by classname fullpost ...
    if( BloggerExt.isListMode() ) {
        // some bugfix jQuery('#fullpost') only return first match ?? why?? change to css selector mode.
        jQuery('div.post-body').each( function (i) {
            if( jQuery(this).find('#fullpost').length == 1 ) {
                if (BloggerExtOptions.replace_continue_markup_as_link) {
                    var postLinkHtml = "<span class='post-body-continue'><a href='"
                                      +jQuery(this).parent().find('.post-title a').attr('href')
                                      +"'>"+BloggerExtOptions.continue_markup_expand_title+"</a></span>";
                    jQuery(this).find('#fullpost').before( jQuery(postLinkHtml) ).remove();

                }else {
                    var postLinkHtml = "<span class=\"post-body-continue\"><a id=\"post-body-toggle" + i + "\" onclick=\"jQuery('.post-body-hide"
                                      +i+"').toggle("+animate_str
									  +"function(){"
									  +"  jQuery(this).is(':hidden') ? "
                                      +"    jQuery('#post-body-toggle"+i+"').html(BloggerExtOptions.continue_markup_expand_title) : "
                                      +"    jQuery('#post-body-toggle"+i+"').html(BloggerExtOptions.continue_markup_collapse_title)"
                                      +"});\">"+BloggerExtOptions.continue_markup_expand_title+"</a></span>";
                    jQuery(this).find('#fullpost').before( jQuery(postLinkHtml) ).addClass("post-body-hide"+i).css('display', 'none');
                }
            }
        });
    }else {
        jQuery('div.post-body #fullpost').each( function (i) {
                jQuery(this).show();
        });
    }
};

BloggerExt.register('replace_continue_markup' ,  {
    replace_continue_markup: true,
	replace_continue_markup_version: 1.0,
	replace_continue_markup_animate: false,
    replace_continue_markup_as_link: false,
    continue_markup_expand_title: '[+] Read More....',
    continue_markup_collapse_title: '[-] Summary....'
});
BloggerExt.registerHook(BloggerExt.replace_continue_markup);


// Register author_comment_highlighting
BloggerExt.author_comment_highlighting = function() {

    if( BloggerExt.isItemMode() ) {
        // try to find profile
        if(BloggerExtOptions.author_comment_highlighting_profile == '') {
            jQuery('.profile-link:first').each(function() {
                    BloggerExtOptions.author_comment_highlighting_profile = jQuery(this).attr('href').split('/')[4];
            });
        }
        if(BloggerExtOptions.author_comment_highlighting_profile != '') {
            var arAuthors = BloggerExtOptions.author_comment_highlighting_profile.split(',');
            jQuery('#comments-block .comment-author').each( function(i) {
                for( var idx in arAuthors) {
                    var author = arAuthors[idx];
                    try{
                        if( ((jQuery(this).find('a:eq(1)').attr('href').split('/'))[4]) == author ) {
                            jQuery(this).next().removeClass().addClass('comment-body-author').css(BloggerExtOptions.author_comment_highlighting_style);
                        }
                    }catch(e){}
                }
            });
        }
    }
};
BloggerExt.register('author_comment_highlighting' ,  {
    author_comment_highlighting: true,
    author_comment_highlighting_version: 0.2,
    author_comment_highlighting_profile: '',
    author_comment_highlighting_style: { 'color': '#C30014', 'font-width': 'bold' }
});


// Register LabelCloud
BloggerExt.labelcloud = function() {

    var arLabels = new Array();
    var arLabelCounts = new Array();
    var labelMaxCount = 0;

    // by delicious
    function s(a,b,i,x){
        if(a>b){ var m=(a-b)/Math.log(x),v=a-Math.floor(Math.log(i)*m); }
        else{ var m=(b-a)/Math.log(x),v=Math.floor(Math.log(i)*m+a); }
        return v;
    }

    jQuery('#'+BloggerExtOptions.labelcloud_widget_id+' div li').each(function(idx){
        var txt = jQuery(this).text();
        var i = txt.indexOf('(');
        var j = txt.indexOf(')');
        var labelCount = txt.substr(i+1, (j-i-1));
        arLabels[idx] = this;
        arLabelCounts[idx] = labelCount;
        if(parseInt(labelCount) > labelMaxCount) labelMaxCount = parseInt(labelCount);
    });
    for (var i=0; i<arLabels.length; i++) {
        var liObj = jQuery(arLabels[i]);
        var aObj = liObj.find('a');
        var v = s(BloggerExtOptions.labelcloud_minFontSize, BloggerExtOptions.labelcloud_maxFontSize, arLabelCounts[i], labelMaxCount);
        var r = s(BloggerExtOptions.labecloud_minColor[0], BloggerExtOptions.labelcloud_maxColor[0], arLabelCounts[i], labelMaxCount);
        var g = s(BloggerExtOptions.labecloud_minColor[1], BloggerExtOptions.labelcloud_maxColor[1], arLabelCounts[i], labelMaxCount);
        var b = s(BloggerExtOptions.labecloud_minColor[2], BloggerExtOptions.labelcloud_maxColor[2], arLabelCounts[i], labelMaxCount);
        if(aObj.length == 1) {
            aObj.css({'font-size': v, 'color': 'RGB('+r+','+g+','+b+')'});
            if (BloggerExtOptions.labelcloud_display_count) aObj.html(aObj.html() + ' (' + arLabelCounts[i]  + ')');
            liObj.html(aObj);
        }else {
            liObj.css({'font-size': v, 'color': 'RGB('+r+','+g+','+b+')'});
        }
        liObj.css({'display': 'inline'});
    }
};
BloggerExt.register('labelcloud' ,  {
    labelcloud: true,
    labelcloud_version: 0.2,
    labelcloud_widget_id: 'Label1',
    labelcloud_maxFontSize: 24,
    labelcloud_minFontSize: 10,
    labelcloud_maxColor: [168,181,248],
    labecloud_minColor: [0,0,0],
    labelcloud_display_count: false
});


// Register sidebar_widget_icon
BloggerExt.sidebar_widget_icon = function() {

    // find containers to expandable.
	for (var widgetId in BloggerExtOptions.sidebar_widget_icons) {
		var widgetImg = BloggerExtOptions.sidebar_widget_icons[widgetId];

        // find widget container with class name
        jQuery('#'+widgetId).each( function(j){
                var titleObj = jQuery(this).children('h2:eq(0)');
                titleObj.prepend(widgetImg);
        });
    }

};
BloggerExt.register('sidebar_widget_icon' ,  {
    sidebar_widget_icon: true,
    sidebar_widget_icons: {}
});


// Register bookmark_buttons
BloggerExt.bookmark_buttons = function() {
    
    // process each posts at ListMode and ItemMode
    jQuery('div.post').each( function (i) {
            var post_titleLinkObj = jQuery(this).find('.post-title a');
            var post_title = encodeURIComponent(post_titleLinkObj.text());
            var post_url = encodeURIComponent(post_titleLinkObj.attr('href'));
            var post_desc = encodeURIComponent(jQuery(this).find('.post-body').text().substr(0,500));

            var buttonsHTML = '';
            for (var i=0; i < BloggerExtOptions.bookmark_buttons_bookmarklets.length; i++) {
                var img = BloggerExtOptions.bookmark_buttons_bookmarklets[i][0];
                var alt = BloggerExtOptions.bookmark_buttons_bookmarklets[i][1];
                var urlTempl = BloggerExtOptions.bookmark_buttons_bookmarklets[i][2];
                
                var url = urlTempl.replace('%URL%', post_url, "gm");
                url = url.replace('%TITLE%', post_title, "gm");
                url = url.replace('%DESC%', post_desc, "gm");
                
                buttonsHTML += '<a class="bookmark_button" href="'+url+'" alt="'+alt+'"><img src="'+img+'" alt="'+alt+'"></a>';
            }
            jQuery(this).find('.post-footer .post-icons').after( BloggerExtOptions.bookmark_buttons_template.replace('%BOOKMARK_BUTTONS%', buttonsHTML, "gm"));
    });
};
BloggerExt.register('bookmark_buttons' ,  {
    bookmark_buttons: true,
    bookmark_buttons_version: 1.0,
    bookmark_buttons_template: '<span class="post-bookmarks">%BOOKMARK_BUTTONS%</span>',
    bookmark_buttons_bookmarklets: [
        [ 
          'http://blogger.ext2.googlepages.com/hemidemi.gif',
          'HEMiDEMi',
          'http://www.hemidemi.com/user_bookmark/new?via=sticker&url=%URL%&title=%TITLE%&description=%DESC%' 
        ] ,
        [ 
          'http://blogger.ext2.googlepages.com/yahoo-myweb.png', 
          'Yahoo',
          'http://tw.myweb2.search.yahoo.com/myresults/bookmarklet?ei=UTF-8&u=%URL%&t=%TITLE%&d=%DESC%'
        ],
        [ 
          'http://blogger.ext2.googlepages.com/myshare.gif', 
          'MyShare',
          'http://myshare.url.com.tw/index.php?func=newurl&from=mysharepop&NewsMaster=1&url=%URL%&desc=%TITLE%&contents=%DESC%' 
        ],
        [ 
          'http://blogger.ext2.googlepages.com/delicious.png', 
          'del.icio.us',
          'http://del.icio.us/post?url=%URL%&title=%TITLE%' 
        ],
        [ 
          'http://blogger.ext2.googlepages.com/technorati.png', 
          'Technotati',
          'http://technorati.com/faves?sub=%TITLE%&add=%URL%' 
        ],
        [ 
          'http://blogger.ext2.googlepages.com/furl.gif', 
          'FURL',
          'http://furl.net/storeIt.jsp?&u=%URL%&t=%TITLE%' 
        ],
        [ 
          'http://blogger.ext2.googlepages.com/digg.png',
          'digg it!',
          'http://www.digg.com/submit?phase=2&url=%URL%&title=%TITLE%' 
        ]
    ]
});
BloggerExt.registerHook(BloggerExt.bookmark_buttons);


// Run All Register Process
BloggerExt.process();
}catch (e) { }

